//============================================================================
// Name        : tbMaskCmp.cpp
// Author      : Thomas Bergmueller
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <opencv2/highgui/highgui.hpp>


using namespace std;
using namespace cv;


int main(int argc, char** argv)
{

	if(argc != 3)
	{
		cout << "You have to call with two parameters in the following form:" << endl;
		cout << "\t tbMaskCmp <groundTruthMask> <toCompare>" << endl;
		return -1;
	}

	Mat gt;
	Mat toCmp;


	gt = imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE);
	if(gt.empty())
	{
		cerr << "Could not load groundtruth from " << argv[1] << endl;
		return -2;
	}

	toCmp = imread(argv[2], CV_LOAD_IMAGE_GRAYSCALE);

	if(toCmp.empty())
	{
		cerr << "Could not load mask to compare from " << argv[2] << endl;
		return -2;
	}


	Mat diff;
	bitwise_xor(gt,toCmp,diff);

	// xor... 1 if different, 0 elsewise... 255;0 in case of grayscales

	// normalize to 0...1, because then
	normalize(diff,diff,0,1,CV_MINMAX);
	//imshow("diff", diff);

	Scalar s;

	// The mean value is the Percentage of wrong pixels
	s = mean(diff);

	cout << "WrongClassificationRatio " << s[0] << endl;

	return 0;
}
